# 每个月第一个交易日买100股，年底全部卖完
import pandas as pd

df = pd.read_csv('./files/前复权./files/茅台.csv')

list = []
list02 = []

def checkMonth(i, j):
  day = 1
  while True:
    date = f'{i}-{str(j).zfill(2)}-{str(day).zfill(2)}'
    day = day + 1
    print(date)
    print(df['date'])
    if(df['date'].isin([date]).any()):
      return date
    
def checkYear(i):
  day = 31
  while True:
    date = f'{i}-12-{str(day).zfill(2)}'
    day = day - 1
    if(df['date'].isin([date]).any()):
      return date


for i in range(2010,2017):
  for j in range(1,13):
    list.append(checkMonth(i, j))
    if(j == 12):
      list02.append(checkYear(i))

buyMonth = df[df['date'].isin(list)]
sellYear = df[df['date'].isin(list02)]

buyMonth['one'] = buyMonth['open'] * 100
sellYear['one'] = sellYear['close'] * 1200

a = buyMonth['one'].sum()
b = sellYear['one'].sum()

print(buyMonth)
print(sellYear)

print(f'总共购买了{a}')
print(f'总共卖出了{b}')

print(f'合计收益是{b - a}')


